package com.hh.flow.mapper;

import com.hh.flow.domain.FlowInstance;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryWrapper;

import java.util.List;

import static com.hh.flow.domain.tables.FlowDefinitionTableDef.flow_definition;
import static com.hh.flow.domain.tables.FlowInstanceTableDef.flow_instance;

/**
 * 流程实例Mapper接口
 *
 * @author hh
 * @date 2023-03-29
 */
public interface FlowInstanceMapper extends BaseMapper<FlowInstance> {

    List<FlowInstance> queryByidWithUpdateLock(List<Long> definitionIds);

    /**
     * 获取流程实例
     * @param flowInstance
     * @return
     */
    default List<FlowInstance> getList(FlowInstance flowInstance)
    {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .select(flow_instance.all_columns)
                .select(flow_definition.flow_name)
                .from(flow_instance).as("t")
                .leftJoin(flow_definition).as("d")
                .on(flow_instance.definition_id.eq(flow_definition.id))
                .orderBy(flow_instance.create_time.desc());
        return selectListByQuery(queryWrapper);
    }
}
